home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / gamekit-1 / ArrayBonusTracker.m < prev    next >
Text File  |  1995-06-12  |  990b  |  53 lines

  1.  
  2. #import <gamekit/gamekit.h>
  3.  
  4. static int _defaultBonusArray = 0;
  5.  
  6. @implementation ArrayBonusTracker
  7.  
  8. - init
  9. {
  10.     return [self initForBonuses:&_defaultBonusArray count:1];
  11. }
  12.  
  13. - initForBonuses:(int *)bonusArray count:(int)num
  14. {    // we copy the array in...
  15.     int i;
  16.     // set up array before super init because it will call resetBonus,
  17.     // which expects this data to be present already.
  18.     if (valuesArray) free(valuesArray);
  19.     valuesArray = (int *)NXZoneMalloc([self zone], sizeof(int) * num);
  20.     for (i=0; i<num; i++) valuesArray[i] = bonusArray[i];
  21.     count = num;
  22.     [super init];
  23.     return self;
  24. }
  25.  
  26. - advanceBonus
  27. {
  28.     bonusIndex++;
  29.     if (bonusIndex >= count) bonusIndex = count - 1;
  30.     value = valuesArray[bonusIndex];
  31.     return self;
  32. }
  33.  
  34. - retreatBonus
  35. {
  36.     bonusIndex--;
  37.     if (bonusIndex < 0) bonusIndex = 0;
  38.     value = valuesArray[bonusIndex];
  39.     return self;
  40. }
  41.  
  42. - setMin:(int)newMin max:(int)newMax { return self; } // No-op
  43.  
  44. - resetBonus
  45. {
  46.     bonusIndex = 0;
  47.     value = valuesArray[bonusIndex];
  48.     return self;
  49. }
  50.  
  51.  
  52. @end
  53.